<?php
//print_r($_FILES);
//print_r($_POST);
$name = $_POST["model_name"];
// upload model
    if (isset($_FILES) && $_FILES["file"]["size"]>=0) {
    //$_POST
        $_POST["model_name"] = $_FILES["file"]["name"];
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_VERBOSE, 0);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible;)");
        curl_setopt($ch, CURLOPT_URL, "http://localhost/wekaws/upload_model_service.php");
        curl_setopt($ch, CURLOPT_POST, true);
        $post = array(
            "file"=>"@".$_FILES["file"]["tmp_name"],
            "model_name" => $_FILES["file"]["name"],
        );
        curl_setopt($ch, CURLOPT_POSTFIELDS, $post); 
        $upload = curl_exec($ch);
        $upload = json_decode($upload);
    }
// upload instance
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_VERBOSE, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible;)");
    curl_setopt($ch, CURLOPT_URL, "http://localhost/wekaws/classify_service.php");
    curl_setopt($ch, CURLOPT_POST, true);
    $data = "";
    $len = count($_POST["data"]);
    for ($i=0; $i<$len; $i++){
        $data .= $_POST["data"][$i];
    }
    $post = array(
        "attributes" => $data,
        "model_name" => $name,
        "weka" => "no",
    );
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post); 
    $result = curl_exec($ch);
    echo $result;
    $result = json_decode($result);
    
// learn new
    if ($_POST["newlearn"] == "yes"){
        
    }
?>

<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE html>
<html>
    <head>
        <title>Mushroom Clasification</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<LINK href="Style.css" rel="stylesheet" type="text/css">
    </head>
    <body>
        <div class="title">
			Classify Your Mushroom Before Eat!
		</div>
                <button onclick="javascript:window.location='Learning.php'" value="Learning"> Learn New Model </button>
                <button onclick="javascript:window.location='Classification.php'" value="Classification"> Classify </button>
                <button onclick="javascript:window.location='download.php'" value="Allmodel"> List All Model </button>

		<hr>
		<div class="content">
			<h3>Classification method :</h3>
			<h3>Data test :</h3>
			<h3>Classification result :</h3>
			<h3>Accuration :</h3>
		</div>
    </body>
</html>
